package com.example.myapplication.volunteerservice;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.MenuItem;

import com.example.myapplication.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class Volunteer extends AppCompatActivity {

    private BottomNavigationView bt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_volunteer);
        initview();
        //碎片切换
        fragmentationswitching();
    }

    private void fragmentationswitching() {
        MynewsFragment mynewsFragment = new MynewsFragment();
        MyFragment myFragment = new MyFragment();
        MyhelpFragment  myhelpFragment= new MyhelpFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.li,mynewsFragment).commit();
        bt.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.mynews:
                        getSupportFragmentManager().beginTransaction().replace(R.id.li,mynewsFragment).commit();
                        break;
                    case R.id.myhelp:
                        getSupportFragmentManager().beginTransaction().replace(R.id.li,myhelpFragment).commit();
                        break;
                    case R.id.my:
                        getSupportFragmentManager().beginTransaction().replace(R.id.li,myFragment).commit();
                        break;
                }
                return true;
            }
        });

    }

    private void initview() {
        bt = findViewById(R.id.bt);
    }
}